package com.gc.gc.menu.controller;

import com.gc.gc.common.control.BaseController;
import com.gc.gc.menu.service.MenuService;
import com.gc.gc.mybatis.entity.PtMenuEntity;
import com.gc.gc.mybatis.ztree.ZtreeEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/menu")
public class MenuController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private MenuService menuService;
    @Secured("ROLE_gqgy_data_menu")
    @RequestMapping("/menuPage")
    public String menuPage(){
        return "menu/menuPage";
    }
    @RequestMapping("/getMenuTree")
    @ResponseBody
    public List<ZtreeEntity> getMenuTree(){
        return menuService.getMenuTree();
    }

    @RequestMapping("/getMenuInfoById")
    @ResponseBody
    public PtMenuEntity getMenuInfoById(@RequestParam("menuId") String menuId){
        logger.info("menuId:" + menuId);
        return menuService.getMenuInfoById(menuId);
    }
    @Secured("ROLE_cldk_data_menu")
    @RequestMapping("/modifyMenuInfoById")
    @ResponseBody
    public String modifyMenuInfoById(PtMenuEntity entity){
        logger.info( entity);
        menuService.modifyMenuInfoById(entity);
        return getSuccessMsg("menu.modify.success");
    }
    @Secured("ROLE_cldk_data_menu")
    @RequestMapping("/addMenuInfoById")
    @ResponseBody
    public String addMenuInfoById(PtMenuEntity entity){
        logger.info( entity);
        menuService.addMenuInfoById(entity);
        return getSuccessMsg("menu.add.success");
    }

}